<template>
	<!-- 扫码点餐 -->
	<view class="" v-if="time<time2"></view>
	<view v-else style="background: #333;height: 100vh;" class="flex-c" @click="scan()">
		<view class="div">
			<image src="/static/ercode.png" mode=""></image>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				time:'',
				time2:''
			};
		},
		onLoad() {
			this.time = Date.parse(new Date()) /1000
			this.time2 = this.$time
			if(this.time<this.time2){
				uni.navigateTo({
					url: '/pages/index'
				})
			}
			this.scan()
			// uni.navigateTo({
			// 	url: '/pageB/scan/index?mch_id='+2+'&table_id='+6
			// })
			
		},
		onShow() {
			uni.setTabBarStyle({backgroundColor:'#333'})
		},
		methods:{
			scan(){
				if(uni.getStorageSync('access_token') == ''){
					this.$utils.isgologin()
					return
				}
				// 扫码
				// 允许从相机和相册扫码
				uni.scanCode({
					scanType: ["qrCode"],
					success: (res) => {
						if (res.result) {
							console.log("扫码结果=========》》》》",res)
							let t = JSON.parse(JSON.stringify(res.result))
							var Request = new Object();
							Request = this.GetRequest(t);
							console.log(Request);
							uni.navigateTo({
								url: '/pageB/scan/index?mch_id='+Request['ttps://guizhouchenxun.com/mini/tables/?mch_id']+'&table_id='+Request.table_id+'&i=1'
							})
				
						} else {
							console.log('请重新扫描');
							return false;
						}
					},
					fail: (res) => {
						console.log('未识别到二维码');
					}
				})
			},
			GetRequest(url) {//获取二维码信息
				let theRequest = new Object();
				if (url.indexOf("?") != -1) {
				let str = url.substr(1);
				let strs = str.split("&");
					for(var i = 0; i < strs.length; i ++) {
						theRequest[strs[i].split("=")[0]] = unescape(strs[i].split("=")[1]);
					}
				}
				return theRequest;
			},
		},
		
		
	}
</script>

<style lang="scss">
.div{
	width: 363rpx;
	height: 345rpx;
	// border: 1px dotted #fff;
	image{
		width: 100%;height: 100%;
	}
}
</style>
